package com.chaos.system.controller;

import com.chaos.system.api.data.TUserData;
import com.chaos.system.service.TUserService;
import com.chaos.framework.model.dto.ID;
import com.chaos.framework.model.dto.page.PageQueryDto;
import com.chaos.framework.model.dto.result.data.BooleanResult;
import com.chaos.framework.model.dto.result.data.DataResult;
import com.chaos.framework.model.dto.result.list.ListResult;
import com.chaos.framework.model.dto.result.page.PageResult;
import com.chaos.framework.starter.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;

/**
 * @author Jacky.Cui
 * @since 2024-11-13
 */
@Slf4j
@RestController
@Api(tags = "C端用户")
@RequestMapping("/tUser")
public class TUserController extends BaseController<TUserData> {
    @Resource
    private TUserService tUserService;

    @PostMapping({"/one.admin", "/one.open", "/one"})
    @ApiOperation(value = "C端用户详情", httpMethod = "POST")
    public DataResult<TUserData> one(@RequestBody ID data) {
        return dataResult(tUserService.selectByID(data));
    }

    @PostMapping("/list")
    @ApiOperation(value = "C端用户列表", httpMethod = "POST")
    public ListResult<TUserData> list(@RequestBody TUserData data) {
        return listResult(tUserService.selectByData(data));
    }

    @PostMapping("/page")
    @ApiOperation(value = "C端用户分页", httpMethod = "POST")
    public PageResult<TUserData> page(@RequestBody PageQueryDto<TUserData> data) {
        return pageResult(tUserService.selectByPage(data));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增C端用户", httpMethod = "POST")
    public DataResult<ID> add(@RequestBody TUserData data) {
        return dataResult(tUserService.insertModel(data));
    }

    @PostMapping("/update")
    @ApiOperation(value = "编辑C端用户", httpMethod = "POST")
    public BooleanResult update(@RequestBody TUserData data) {
        return booleanResult(tUserService.updateModelByID(data));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除C端用户", httpMethod = "POST")
    public BooleanResult delete(@RequestBody ID data) {
        return booleanResult(tUserService.deleteModel(data));
    }

}
